


#include "log.h"
#include "stdint.h" 


#define hPRINTF_PORT huart4


#ifdef __GNUC__
  /* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
     set to 'Yes') calls __io_putchar() */
  #define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
  #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif /* __GNUC__ */


/**
*��ӳ��fputc
*/
#if 0
PUTCHAR_PROTOTYPE
{
		
	 HAL_UART_Transmit(&hPRINTF_PORT, (uint8_t *)&ch, 1, 0xFFFF);
	 
	return ch;
}
#endif

int fputc(int ch, FILE *f)
{      
	

	while((huart4.Instance->SR&UART_FLAG_TXE)==0);
	huart4.Instance->DR = (u8) ch;  
	while((huart4.Instance->SR&UART_FLAG_TC)==0);
	return ch;
}








/**
  * ��������: �ض���c�⺯��scanf
  * �������: ��
  * �� �� ֵ: ��
  * ˵    ������
  */
int fgetc(FILE * f)
{
  uint8_t ch = 0;
  HAL_UART_Receive(&hPRINTF_PORT,  (uint8_t *)&ch, 1, 0xffff);
  printf("%c",ch);
  return ch;
}



void GetCmd(char *pcGetCmd )
{
	
	logn();
	logred("input cmd :\r\n"); 
	scanf("%[^\r]",pcGetCmd);
	//scanf("%*[^\n]",pcGetCmd); //��ʾ�������в��ǻ��е��ַ�
	logyellow("%s",pcGetCmd);
	logn();
}


void InitLog(void)
{

	 g_ptMutex = xSemaphoreCreateMutex();
	 if( NULL == g_ptMutex )
	 {

	 	printf("mutex malloc fail");
	 }
	
}




void LogTakeMutex(void)//(SemaphoreHandle_t ptMutex)
{

	BaseType_t tMuxReturn = pdFALSE; 

	if( NULL == g_ptMutex )
	{
		//logerr("the ptMutex pointer is null");
		return;
	}
	
	tMuxReturn = xSemaphoreTake( g_ptMutex  , portMAX_DELAY);


	
}





void LogGiveMutex(void)//(SemaphoreHandle_t ptMutex)
{
	
	BaseType_t tMuxReturn = pdFALSE; 

	tMuxReturn = xSemaphoreGive(g_ptMutex);

}




